﻿using System;
using System.Collections.Generic;

namespace FDEE.Model
{
    class CPTM1 : CPTMBase
    {
        double spaceAlignW, spaceAlignL;
        eSubType eTh;
        internal CPTM1(string typeName, string pierNumber, eColumnType ct, eSubType st,
            int ww, int ll, int hh, int rr, double up, double low,
            eDB mainDB)
            : base(typeName, pierNumber,ct, st, ww, ll, hh, rr, up, low, mainDB)
        {
            eTh = st;
        }

        public override void SetRebarDistribute()
        {
            double d1, d2;
            switch (eTh)
            {
                case eSubType.A:
                    d1 = (Length - Radius * 2) / 10;
                    d2 = (Width - Radius * 2) / 7;
                    spaceAlignW = d2;
                    spaceAlignL = d1;
                    MainLBarDistribute = new RebarTendonDistribute(32, d1, 10);
                    AddLBarDistribute = new RebarTendonDistribute(32,  new List<double>() { d1, 3 * d1, 2 * d1, 3 * d1, d1 }, 1, 1);
                    MainWBarDistribute = new RebarTendonDistribute(32, new List<double>() { d1, 2* d1,  d1, 2 * d1, d1 }, 0, 0);
                    AddWBarDistribute = new RebarTendonDistribute(32, new List<double>() { });
                    MainLBarDistributeB= new RebarTendonDistribute(32, d1, 10);
                    MainLBarDistributeB.Location= MainLBarDistribute.Delete(new List<int>() { 2,5,8});
                    AddLBarDistributeB = new RebarTendonDistribute(32, new List<double>() { });
                    MainWBarDistributeB = new RebarTendonDistribute(32, new List<double>() { d1, 2 * d1, d1, 2 * d1, d1 }, 0, 0); 
                    AddWBarDistributeB = new RebarTendonDistribute(32, new List<double>() { });
                    MainLBarDistributeC = new RebarTendonDistribute(32, d1, 10);
                    MainLBarDistributeC.Location = MainLBarDistribute.Delete(new List<int>() { 2, 5, 8 });
                    AddLBarDistributeC = new RebarTendonDistribute(32, new List<double>() { });
                    MainWBarDistributeC = new RebarTendonDistribute(32, new List<double>() { d1, 2 * d1, d1, 2 * d1, d1 }, 0, 0);
                    AddWBarDistributeC = new RebarTendonDistribute(32, new List<double>() { });
                    break;
                case eSubType.B:
                    d1 = (Length - Radius * 2) / 10;
                    d2 = (Width - Radius * 2) / 7;
                    spaceAlignW = d2;
                    spaceAlignL = d1;
                    MainLBarDistribute = new RebarTendonDistribute(32, new List<double>(){ d1,2 * d1, d1, 2*d1, 2 * d1,d1 }, 0, 0);
                    AddLBarDistribute = new RebarTendonDistribute(32, new List<double>() { 3*d1,  d1,  2 * d1,d1,3* d1 }, 3, 3);
                    MainWBarDistribute = new RebarTendonDistribute(32, d2,7);
                    AddWBarDistribute = new RebarTendonDistribute(32, new List<double>() { });

                    MainLBarDistributeB = new RebarTendonDistribute(32, new List<double>() { d1, 2 * d1, d1, d1, d1,d1, 2 * d1,  d1 }, 0, 0);
                    AddLBarDistributeB = new RebarTendonDistribute(32, new List<double>() { });
                    MainWBarDistributeB = new RebarTendonDistribute(32, new List<double>() { d2, 2 * d1, d1, d1, d1, d1, 2 * d1, d1 }, 0, 0);
                    AddWBarDistributeB = new RebarTendonDistribute(32, new List<double>() { });
                    MainLBarDistributeC = new RebarTendonDistribute(32, d1, 8);
                    AddLBarDistributeC = new RebarTendonDistribute(32, new List<double>() { });
                    MainWBarDistributeC = new RebarTendonDistribute(32, d2, 5);
                    AddWBarDistributeC = new RebarTendonDistribute(32, new List<double>() { });
                    break;
                case eSubType.C:
                    d1 = (Length - Radius * 2) / 7;
                    d2 = (Width - Radius * 2) / 7;
                    spaceAlignW = d2;
                    spaceAlignL = d1;
                    MainLBarDistribute = new RebarTendonDistribute(32, d1, 7);
                    AddLBarDistribute = new RebarTendonDistribute(32, new List<double>() { 2 * d1, d1, d1, d1, 2 * d1 }, 2, 2);
                    MainWBarDistribute = new RebarTendonDistribute(32, d2, 7);
                    AddWBarDistribute = new RebarTendonDistribute(32, new List<double>() { });
                    d1 = (Length - Radius * 2) / 8;
                    d2 = (Width - Radius * 2) / 5;
                    MainLBarDistributeB = new RebarTendonDistribute(32, d1, 8);
                    AddLBarDistributeB = new RebarTendonDistribute(32, new List<double>() { });
                    MainWBarDistributeB = new RebarTendonDistribute(32, d2, 5);
                    AddWBarDistributeB = new RebarTendonDistribute(32, new List<double>() { });
                    MainLBarDistributeC = new RebarTendonDistribute(32, d1, 8);
                    AddLBarDistributeC = new RebarTendonDistribute(32, new List<double>() { });
                    MainWBarDistributeC = new RebarTendonDistribute(32, d2, 5);
                    AddWBarDistributeC = new RebarTendonDistribute(32, new List<double>() { });
                    break;
                case eSubType.D:
                    d1 = (Length - Radius * 2) / 12;
                    d2 = (Width - Radius * 2) / 7;
                    spaceAlignW = d2;
                    spaceAlignL = d1;
                    MainLBarDistribute = new RebarTendonDistribute(32, d1, 12);
                    AddLBarDistribute = new RebarTendonDistribute(32, new List<double>() { d1, 2 * d1, 2 * d1,  d1, d1, 2 * d1, 2 * d1 ,d1}, 1, 1);
                    MainWBarDistribute = new RebarTendonDistribute(32,d2,7);
                    AddWBarDistribute = new RebarTendonDistribute(32, new List<double>() { });
                    MainLBarDistributeB = new RebarTendonDistribute(32, d1, 9);
                    AddLBarDistributeB = new RebarTendonDistribute(32, new List<double>() { });
                    MainWBarDistributeB = new RebarTendonDistribute(32, d2, 7);
                    AddWBarDistributeB = new RebarTendonDistribute(32, new List<double>() { });
                    MainLBarDistributeC = new RebarTendonDistribute(32, d1, 9);
                    AddLBarDistributeC = new RebarTendonDistribute(32, new List<double>() { });
                    MainWBarDistributeC = new RebarTendonDistribute(32, d2, 7);
                    AddWBarDistributeC = new RebarTendonDistribute(32, new List<double>() { });
                    break;
            }
        }

        public override void SetRebarList()
        {
            #region 0-箍筋
            int npts = GetStirrupNum();
            RebarList.Add(new MORebarRecord(1, 0, "", eDB.DB12, npts, eShapeType.MO, Length - 100 - 24, (int)Math.Round(spaceAlignW * 3 + 12)));
            RebarList.Add(new MORebarRecord(2, 0, "", eDB.DB12, npts, eShapeType.MO, Length - 100 - 24, (int)Math.Round(spaceAlignW * 1 + 12)));
            RebarList.Add(new MORebarRecord(3, 0, "", eDB.DB12, npts * 3, eShapeType.MO, Width - 100 - 24, (int)Math.Round(spaceAlignL * 1 + 12)));
            RebarList.Add(new MORebarRecord(4, 0, "", eDB.DB12, npts * 4, eShapeType.MO, Length - 100 - 24, Width - 100 - 24, 138));
            #endregion

            #region 1-获取承台尺寸
            FootingBase theFooting = MemberFactory.CreatMember(MemberFactory.FromColumnToFooting(ColumnType), SubType);
            int FTHeight = theFooting.Height;
            int FTWidth = theFooting.Width;
            int db = (int)MainRebarDB;
            #endregion

            #region 2-分析分段
            int Z1 = 9000 - (FTHeight - 185 + 600 - 3 * db) - 1200; // 搭接节点 1
            int L2 = 0;// 盖梁锚固筋长度；
            if (PierHeight - Z1 - 1500 + 1200 > 12000 - 1500)
            {
                // 分3节
                throw new Exception("分3节还没写");
            }
            else
            {
                // 分2节
                L2 = 1500 + (PierHeight - Z1) + 1200; // 深入盖梁钢筋总长度
            }
            #endregion

            #region
            // 起步筋分类
            int NumOFout=0;// 外向起步筋
            //int main
            if ((FTWidth-Width)*0.5>=600)
            {
                NumOFout += MainLBarDistributeC.Location.Count * 2;                
            }
            int NumAdd = AddLBarDistributeC.Location.Count * 2 + AddWBarDistributeC.Location.Count * 2;
            //5.1a为外侧起步筋；
            RebarList.Add(new MHXRebarRecord(5, 1, "a", MainRebarDB, false, NumOFout, eShapeType.MHXe));
            //5.1b为内侧起步筋，所有加强筋为内侧起步；
            RebarList.Add(new MHXRebarRecord(5, 1, "b", MainRebarDB, true, NumAll - NumOFout + NumAdd, eShapeType.MHX));
            #endregion

            #region 4-锚固筋
            CrossbeamBase theCB = MemberFactory.CreatMember(MemberFactory.ColumnToCrossBeam(ColumnType),0,0);
            NumAll = MainLBarDistribute.Location.Count * 2 + MainWBarDistribute.Location.Count * 2 + 4;
            int NumAddAll = AddWBarDistribute.Location.Count * 2 + AddLBarDistribute.Location.Count * 2;
            int NumL = 0;

            if (Math.Abs(Length-50-12-16-theCB.TendonDistribute.Location[0]*-1)<=theCB.TendonDistribute.Diameter*0.5)
            {
                // 外侧主筋L型避让
                NumL += MainWBarDistribute.Location.Count * 2 + 4;
            }

            // 5.2a为直线锚固
            #endregion

        }
    }

}
